package com.step.io;

import android.content.res.AssetManager;
import android.os.Environment;

public class Files{
	public enum FileType {
		/** 相对于类文件路径*/
		Classpath,

		/** 相对于asset文件夹路径*/
		Internal,

		/** 相对于SD卡路径*/
		External,

		/** 绝对路径*/
		Absolute,
		
		/** 相对于私有文件路径*/
		Local;
	}
	
	protected final String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
	protected final String localpath;
	
	protected final AssetManager assets;

	public Files (AssetManager assets) {
		this.assets = assets;
		localpath = sdcard;
	}
	
	public Files (AssetManager assets, String localpath) {
		this.assets = assets;
		this.localpath = localpath.endsWith("/") ? localpath : localpath + "/";
	}

	public FileHandle getFileHandle (String path, FileType type) {
		return new AssetsHandle(type == FileType.Internal ? assets : null, path, type);
	}

	public FileHandle classpath (String path) {
		return new AssetsHandle(null, path, FileType.Classpath);
	}

	public FileHandle internal (String path) {
		return new AssetsHandle(assets, path, FileType.Internal);
	}

	public FileHandle external (String path) {
		return new AssetsHandle(null, path, FileType.External);
	}

	public FileHandle absolute (String path) {
		return new AssetsHandle(null, path, FileType.Absolute);
	}

	public FileHandle local (String path) {
		path = localpath + path;
		return new AssetsHandle(null, path, FileType.Local);
	}
	
	public String getExternalStoragePath () {
		return sdcard;
	}

	public boolean isExternalStorageAvailable () {
		return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
	}
	
	public String getLocalStoragePath () {
		return localpath;
	}

	public boolean isLocalStorageAvailable () {
		return true;
	}	
}
